package com.jcl.recruit.resume.logic;

import com.jcl.core.utils.CollectionUtils;
import com.jcl.recruit.resume.mapper.ResumeEvaluateMapper;
import com.jcl.recruit.resume.model.ResumeEvaluate;
import com.jcl.recruit.user.logic.UserLogic;
import com.jcl.recruit.user.model.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @ClassName ResumeEvaluateLogic
 * @Description TODO
 * @Author yyliu
 * @Date 2018/9/17 10:00
 * @Version 1.0
 **/
@Component
public class ResumeEvaluateLogic implements ResumeEvaluateMapper {

    @Autowired
    private ResumeEvaluateMapper resumeEvaluateMapper;

    @Autowired
    private UserLogic userLogic;

    public List<ResumeEvaluate> contractDetailList(String corpCode, List<ResumeEvaluate> evaluates){
        if(CollectionUtils.isNotEmpty(evaluates)){
            List<Integer> userIds = new ArrayList<>();
            for(ResumeEvaluate evaluate: evaluates){
                if(!userIds.contains(evaluate.getAddUser()) && null != evaluate.getAddUser()){
                    userIds.add(evaluate.getAddUser());
                }
            }

            Map<Integer, User> userMap =  userLogic.getUserMap(corpCode, userIds);

            for(ResumeEvaluate evaluate: evaluates){
                User user = userMap.get(evaluate.getAddUser());
                if(null != user){
                    evaluate.setAddUserName(user.getRealname());
                }
            }
        }
        return evaluates;
    }

    @Override
    public List<ResumeEvaluate> findList(String corpCode, int resumeId) {
        return resumeEvaluateMapper.findList(corpCode, resumeId);
    }

    @Override
    public int add(ResumeEvaluate resumeEvaluate) {
        return resumeEvaluateMapper.add(resumeEvaluate);
    }


}
